﻿using BLL;
using Config;
using DBUtility;
using gfLibrary;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.Login
{
    public partial class LoginResend : System.Web.UI.Page
    {
        private static string wrdkey { get; set; }

        private static string drpkey { get; set; }

        private static string info { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                
            }

            LoadList();
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;

            DataTable m_dtTable = GreatPager1.BindDataTablePage();
            rptList.DataSource = m_dtTable;
            rptList.DataBind();
        }


        private void LoadList()
        {
            string strSql = "SELECT * FROM  VEHICLE_DISPATCH WHERE JCXH = 6 ";

            string strSearchKey = txtKeywords.Text.Trim();
            if (strSearchKey.Length > 0)
            {
                strSql += "and ";
                strSql += "(HPHM like '%" + strSearchKey + "%'";
                strSql += " or AJLSH like '%" + strSearchKey + "%'";
                strSql += " or JCLSH like '%" + strSearchKey + "%'";
                strSql += " or VIN like '%" + strSearchKey + "%')";
            }
            strSql += " ORDER BY ID DESC";

            DataTable dt = new DataTable();
            GreatPager1.BindDataTablePage(ref dt, AppConfig.g_strConnectionStringSqlClient, strSql, 20);
            rptList.DataSource = dt;
            rptList.DataBind();
            dt.Dispose();
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "xxxe", "getSelect();", true);
        }
  

      
        protected void Timer1_Tick(object sender, EventArgs e)
        {
     
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            string strUniqueKey = txtUniqueKey.Value;
            if ((strUniqueKey == null) || (strUniqueKey.Length == 0) || (gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            string strSql = string.Format("UPDATE  VEHICLE_DISPATCH SET JCZT_STATUS = 1,YJXM = '',FJXM = '' WHERE ID = {0}", strUniqueKey);
            if (DbHelper.ExecuteSql(strSql))
            {
                UpdatePrint(strUniqueKey);
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "重新发送成功");
            }
            else
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "重新发送失败");
            }
        }

        private void UpdatePrint(string id)
        {
            string strGetIDSql = string.Format("  SELECT ID FROM RESULT_VEHICLE_INFO WHERE JCLSH = (SELECT JCLSH FROM VEHICLE_DISPATCH WHERE ID = {0})",id);

           string strDeleteSql = string.Format("DELETE FROM PRINT_RECORD  WHERE DISPATCH_ID = {0}", DbHelper.GetValue(strGetIDSql));
            DbHelper.ExecuteSql(strDeleteSql);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            LoadList();
        }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = string.Empty;
            LoadList();
        }

    }
}